var len = 0;
var WS = function(opt){
    var regexp = opt.regexp || /\S/,
        el = $(opt.el),
        list = el.val() ? el.val().split(','): [],
        holder = $('<span class="words-split"></span>'),
        add = $('<a href="javascript:void(0)" class="words-split-add"><i class="mdi mdi-plus"></i></a>');
    if (list.length) {
        for (let i=0;i<list.length;i++) {
            if (!list[i]) {
                list.splice(i, 1);
                i--;
            }
        }
        for (let m=0;m<list.length;m++) {
            holder.append( $('<a href="javascript:void(0)" class="fm-button">'+list[m]+'<em> </em></a>') );
        }
        len = list.length;
    } else {
        len = 0;
    }
    el.hide().after( holder );
    holder.after(add);
    holder.on('click','a>em',function(){
        $(this).parent().remove();
        el.val( holder.text().match(/\S+/g).join(',') )
    });
    add.on('click',function(){
        $(this).hide();
        holder.append( $('<span class="lbl-input" contenteditable="true"/>') )
    });
    holder.on('blur','.lbl-input',function(){	//验证添加字段
        var t = $(this),v = t.text();
        if( regexp.test(v) ){
            t.remove();
            add.show();
            holder.append( $('<a href="javascript:void(0)" class="fm-button">'+v+'<em> </em></a>') );
            el.val( holder.text().match(/\S+/g).join(',') )
        }else if(!v){
            t.remove();
            add.show();
        }else{
            alert('输入不合法');
        }
    });

    holder.on('keydown','.lbl-input',function(e){
        switch(e.keyCode){
            case 13:
            case 27: $(this).trigger('blur');
        }
    });
};
if (!len) {
    WS({
        el: "#staticPath2",
    });
}